package com.hf.lookatme.zmodel.impls;

import android.content.Context;

import com.hf.lookatme.utils.DBExecutor;
import com.hf.lookatme.zbean.RegionData;
import com.hf.lookatme.zmodel.IModel_RegionData;
import com.hf.lookatme.zmodel.loadlistener.OnLoadRegionDataListener;
import com.orhanobut.logger.Logger;

import java.util.List;

/**
 * Created by JoeShiguang on 2015/6/10.
 */
public class Model_RegionData implements IModel_RegionData {


  @Override
  public void getProvinceData(Context context, OnLoadRegionDataListener loadRegionDataListener) {
    List<RegionData> list_province = null;

    try {
      list_province = DBExecutor.getProvinceData();
      if (list_province != null && list_province.size() > 0) {
        loadRegionDataListener.onLoadProvinceDataSuccess(list_province);
      } else {
        loadRegionDataListener.onLoadProvinceDataFailed("getInfoFromDBFailed");
      }
    } catch (Exception ex) {
      Logger.e(ex.getMessage());
      loadRegionDataListener.onLoadProvinceDataFailed("getInfoFromDBFailed");
    }
  }

  @Override
  public void getCityData(Context context, OnLoadRegionDataListener loadRegionDataListener, int provinceID) {

    List<RegionData> list_city = null;

    try {
      list_city = DBExecutor.getCityData(provinceID);
      if (list_city != null && list_city.size() > 0) {
        loadRegionDataListener.onLoadCityDataSuccess(list_city);
      } else {
        loadRegionDataListener.onLoadCityDataFailed("getInfoFromDBFailed");
      }
    } catch (Exception ex) {
      Logger.e(ex.getMessage());
      loadRegionDataListener.onLoadCityDataFailed("getInfoFromDBFailed");
    }
  }

  @Override
  public void getAreaData(Context context, OnLoadRegionDataListener loadRegionDataListener, int cityID) {

    List<RegionData> list_area = null;

    try {
      list_area = DBExecutor.getAreaData(cityID);
      if (list_area != null && list_area.size() > 0) {
        loadRegionDataListener.onLoadAreaDataSuccess(list_area);
      } else {
        loadRegionDataListener.onLoadAreaDataFailed("getInfoFromDBFailed");
      }
    } catch (Exception ex) {
      Logger.e(ex.getMessage());
      loadRegionDataListener.onLoadAreaDataFailed("getInfoFromDBFailed");
    }
  }
}
